package ppjava12v1.chess.entities.games;

import ppjava12v1.chess.enums.FigureType;
import ppjava12v1.chess.enums.Side;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Класс описывающий ходы в партии
 * - Партия
 * - Номер хода
 * - Кто ходит
 * - Фигура
 * - Откуда
 * - Куда
 */
@Entity
@Table(name = "moves", uniqueConstraints = {
        @UniqueConstraint(name = "uk_game_number_side",
                columnNames = {"game_id", "move_number", "side"})})
public class Move implements Serializable {

    @Id
    @GeneratedValue
    private long id;

    @Column(name = "move_number")
    private int moveNumber;

    @Column
    private Side side;

    @ManyToOne(targetEntity = Game.class)
    @JoinColumn(name = "game_id")
    private Game game;

    @Column(name = "figure")
    private FigureType figure;

    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "row", column = @Column(name = "from_row")),
            @AttributeOverride(name = "col", column = @Column(name = "from_col"))})
    private Coordinate from;

    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "row", column = @Column(name = "to_row")),
            @AttributeOverride(name = "col", column = @Column(name = "to_col"))})
    private Coordinate to;

    public Move() {
    }

    public Move(Game game, int moveNumber, Side side, FigureType figure, Coordinate from, Coordinate to) {
        this.game = game;
        this.moveNumber = moveNumber;
        this.side = side;
        this.figure = figure;
        this.from = from;
        this.to = to;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getMoveNumber() {
        return moveNumber;
    }

    public void setMoveNumber(int moveNumber) {
        this.moveNumber = moveNumber;
    }

    public Side getSide() {
        return side;
    }

    public void setSide(Side side) {
        this.side = side;
    }

    public Game getGame() {
        return game;
    }

    public void setGame(Game game) {
        this.game = game;
    }

    public FigureType getFigure() {
        return figure;
    }

    public void setFigure(FigureType figure) {
        this.figure = figure;
    }

    public Coordinate getFrom() {
        return from;
    }

    public void setFrom(Coordinate from) {
        this.from = from;
    }

    public Coordinate getTo() {
        return to;
    }

    public void setTo(Coordinate to) {
        this.to = to;
    }

}
